//
//  LLHomeTitleButton.swift
//  LLWeibo09
//
//  Created by 林 on 16/4/1.
//  Copyright © 2016年 lin. All rights reserved.
//

import UIKit

class LLHomeTitleButton: UIButton {

     // 便利构造函数,调用当前类的便利构造函数
    convenience init(title: String?, imageName: String) {
        self.init()
        setTitle(title, forState: UIControlState.Normal)
        setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        sizeToFit()
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        // 1.将label移动到最左边
        //        var frame = self.titleLabel!.frame
        //        frame = CGRect(x: 0, y: 0, width: frame.size.width, height: frame.size.height)
        //        self.titleLabel!.frame = frame
        // Swift可以直接设置结构体里面的成员
        titleLabel!.frame.origin.x = 0
        
        // 2.图片移动到label后面
        imageView?.frame.origin.x = titleLabel!.frame.width + 3
    }

}
